﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DADOS.auxiliares;
using DADOS.esf;

namespace PROAD.admin.Consulta
{
    public partial class ConsultaListaEsf : System.Web.UI.Page
    {

        metEndereco metEndereco = new metEndereco();

        metEsf metEquipe = new metEsf();

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                CarregarDdlUf();
                CarregarGrid();
            }
        }

        /// <summary>
        /// Carregar a DDL UF
        /// </summary>
        protected void CarregarDdlUf()
        {
            var list = metEndereco.ListaUF();
            ddlUf.DataSource = list;
            ddlUf.DataBind();
            ddlUf.Items.Insert(0, new ListItem("Todas UF", "0"));
        }

        protected void CarregarGrid()
        {
            var list = metEquipe.ListarES(txtNomeEs.Text, txtArea.Text, txtUs.Text, ddlUf.SelectedValue);
            gridEs.DataSource = list;
            gridEs.DataBind();
        }

        protected void btnPesquisar_Click(object sender, EventArgs e)
        {
            CarregarGrid();
        }

        protected void gridEs_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);

            switch (e.CommandName)
            {
                case "Editar":
                    Response.Redirect("/admin/Forms/FormEsf.aspx?cod=" + id);
                    break;
                case "Status":
                    metEquipe.TrocarStatus(id);
                    CarregarGrid();
                    break;
            }
        }
    }
}